<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<title>添加用户</title>
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="format-detection" content="telephone=no">
		<link rel="stylesheet" href="../plugins/layui/css/layui.css" media="all" />
		<link rel="stylesheet" href="../plugins/font-awesome/css/font-awesome.min.css">
	</head>

	<body>
		<div style="margin: 15px;">
			<blockquote class="layui-elem-quote">
				<a href="javascript:history.go(-1);;" class="layui-btn layui-btn-small">
					<i class="layui-icon">&#xe608;</i> 返回
				</a>
			</blockquote>

			<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
				<legend>添加用户</legend>
			</fieldset>

			<form class="layui-form" action="">
				<div class="layui-form-item">
					<label class="layui-form-label">邮箱</label>
					<div class="layui-input-block">
						<input type="text" name="Email" lay-verify="title" autocomplete="off" class="layui-input">
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-label">密码</label>
					<div class="layui-input-block">
						<input type="password" name="Password" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-label">用户名</label>
					<div class="layui-input-inline">
						<input type="tel" name="Name" lay-verify="phone" autocomplete="off" class="layui-input">
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-label">手机号</label>
					<div class="layui-input-inline">
						<input type="text" name="Phone" lay-verify="email" autocomplete="off" class="layui-input">
					</div>
				</div>

			</form>
			<div class="layui-form-item">
				<div class="layui-input-block">
					<button class="layui-btn" id="add" lay-submit="" lay-filter="demo1">添加</button>
				</div>
			</div>
		</div>

		<!--模板-->
		<script type="text/javascript" src="/admin/plugins/layui/layui.js"></script>
		<script type="text/javascript" src="/js/jquery.min.js"></script>
		<script type="text/javascript" src="/js/template.js"></script>
		<script type="text/javascript" src="/admin/js/publish.js"></script>
		<script>
			layui.use('layer', function() {
				var layer = layui.layer;
			});
			$("#add").click(function() {
				var email = $("input[name='Email']").val();
				var emailRegx = /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/;
				if(!emailRegx.test(email)) {
					toast("请输入正确的邮箱");
					return;
				} else {
					var res;
					$.ajax({
						'url': '/user/emailno?Email=' + email,
						'dataType': 'json',
						'async': false,
						'success': function(response) {
							res = response;
						}
					});
					if(res.code === 500) {
						toast(res.msg);
						return;
					}
				}
				
				//检查密码
				var password = $("input[name='Password']").val();
				if(password==null||password==""){
					toast("请输入密码");
					return;
				}
				
				if(password.length<6){
					toast("密码长度不能小于6位");
					return;
				}
								
				var name= $("input[name='Name']").val();
				if(name==null||name==""){
					toast("请输入姓名");
					return;
				}
				
				var phoneRegx = /^1\d{10}$/;
				var phone= $("input[name='Phone']").val();
				if(!phoneRegx.test(phone)){
					toast("请输入正确的手机号");
					return;
				}
				
				//添加
				$.ajax({
					url:"/user/addManage",
					data:$("form").serialize(),
					type:'get',
					dataType:'json',
					success:function(response){
						//console.log(response);
						if(response.code==200){
						
							toast("添加成功");
						}else{
							toast("添加失败");
						}
					}
				});
			});
		</script>
	</body>

</html>